package uk.ac.bath.machines.bool;







import java.io.StringWriter;
import uk.ac.bath.legacy.Value;
import uk.ac.bath.legacy.VectorState;

import uk.ac.bath.legacy.Operator;
import uk.ac.bath.legacy.Parametered;

public class Int extends Operator implements Parametered {

    double sum=0.0;
    double decay=0.0;
    
    public void tick(VectorState in,VectorState out) {


	sum = sum * decay + in.at(1).val;
	if (sum > LogicalMachine.maxValue.doubleValue()) sum = LogicalMachine.maxValue.doubleValue();
	out.at(0).set(sum);
    }


    public void tick(VectorState in,VectorState out,int map[]) {


	sum = sum * decay + in.v[map[1]].val;
	if (sum > LogicalMachine.maxValue.doubleValue()) sum = LogicalMachine.maxValue.doubleValue();
	out.v[map[0]].set(sum);
    }

    public int getStateSize() {
        return 2;
    }


    public int getParamSize() {
        return 1;
    }

    public void setParamAt(Value v,int i) {
	this.decay=v.val/LogicalMachine.maxValue.doubleValue(); ;
    }

    
    public Object clone() {
        return new Int();   // this has state
    }

    public void toString(StringWriter w) {
        w.write("Int ");
    }

}
